package reference.weak;


import java.lang.ref.ReferenceQueue;
import java.lang.ref.WeakReference;

public class ReferenceQueueTest {
    public static void main(String[] args) {
        ReferenceQueue<Object> referenceQueue = new ReferenceQueue<>();
        WeakReference<Object> weakReference = new WeakReference<>(new String("123"), referenceQueue);
        System.out.println(weakReference.get());
        weakReference.enqueue();
        System.gc();
        System.out.println(weakReference.isEnqueued());
        System.out.println(referenceQueue.poll().get());
        System.out.println(weakReference.get());
    }
}
